package com.hqyj.order.service.impl;

import com.hqyj.order.mapper.OrderInfoMapper;
import com.hqyj.order.model.OrderInfo;
import com.hqyj.order.service.OrderInfoService;
import com.hqyj.product.mapper.ProductInfoMapper;
import com.hqyj.sale.mapper.SaleInfoMapper;
import com.hqyj.sale.model.SaleInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author cz
 * 2021/9/6 14:47
 */
@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderInfoMapper orderInfoMapper;
    @Autowired
    private SaleInfoMapper saleInfoMapper;
    @Autowired
    private ProductInfoMapper productInfoMapper;

    @Override
    public List<OrderInfo> queryAllOrderInfo() {
        return orderInfoMapper.queryAllOrderInfo();
    }

    @Override
    public OrderInfo queryOrderInfoById(int id) {
        return orderInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateOrderInfoByOrderInfo(OrderInfo orderInfo) {
        return orderInfoMapper.updateByPrimaryKeySelective(orderInfo);
    }

    @Override
    public int addOrderInfoByOrderInfo(OrderInfo orderInfo) {
        return orderInfoMapper.insertSelective(orderInfo);
    }

    @Override
    public int addSaleInfoByOrderInfo(OrderInfo orderInfo) {
        SaleInfo saleInfo = new SaleInfo();
        saleInfo.setSaleNumber(orderInfo.getId()+2000);
        saleInfo.setProductName(orderInfo.getProductName());
        saleInfo.setUserName(orderInfo.getOrderCustomer());
        saleInfo.setSaleAmount(orderInfo.getOrderQuantity());
        saleInfo.setSalePrice(orderInfo.getOrderPrice());
        saleInfo.setOrderId(orderInfo.getOrderNo());
        saleInfo.setActionName(orderInfo.getActionName());
        return saleInfoMapper.insertSelective(saleInfo);
    }

    @Override
    public int updateOrderInfoStateBySaleId(int id) {
        return orderInfoMapper.updateOrderInfoStateBySaleId(id);
    }

    @Override
    public List<OrderInfo> queryAllOrderInfoBySended() {
        return orderInfoMapper.queryAllOrderInfoBySended();
    }

    @Override
    public int deleteOrderInfoByid(int id) {
        return orderInfoMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateOrderInfoByOrderState(int id) {
        return orderInfoMapper.updateOrderInfoByOrderState(id);
    }


}
